package com.dg.demo.controller;

import com.dg.demo.service.impl.DemoService;
import com.dg.framework.annotation.DGAutowired;
import com.dg.framework.annotation.DGController;
import com.dg.framework.annotation.DGRequestMapping;
import com.dg.framework.annotation.DGRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@DGController
@DGRequestMapping("/demo")
public class DemoController {
	
	@DGAutowired
	private DemoService demoService;
	
	@DGRequestMapping("/query")
	public void query(HttpServletRequest req, HttpServletResponse resp,
	                  @DGRequestParam("name") String name) {
		String result = " hello work " + name;
		try {
			resp.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@DGRequestMapping("/add")
	public void add(HttpServletRequest req, HttpServletResponse resp,
	                @DGRequestParam("a") Integer a, @DGRequestParam("b") Integer b) {
		try {
			resp.getWriter().write(a + "+" + b + "=" + (a + b));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@DGRequestMapping("/sub")
	public void sub(HttpServletRequest req, HttpServletResponse resp,
	                @DGRequestParam("a") Double a, @DGRequestParam("b") Double b) {
		try {
			resp.getWriter().write(a + "-" + b + "=" + (a - b));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@DGRequestMapping("/remove")
	public String remove(@DGRequestParam("id") Integer id) {
		return "" + id;
	}
	
}
